package com.apexwear.apexutils.adapter;

import android.content.Context;
import android.content.Intent;
import android.text.format.Time;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.apexwear.apexutils.R;
import com.apexwear.apexutils.ui.PersonActivity;
import com.apexwear.apexutils.ui.ReminderActivity;
import com.apexwear.apexutils.ui.ResetActivity;
import com.apexwear.apexutils.ui.ScreenOutActivity;
import com.apexwear.apexutils.ui.TimeActivity;
import com.apexwear.apexutils.ui.WeatherActivity;

public class AdapterTestList extends RecyclerView.Adapter<AdapterTestList.PageHold> {
    String[] pagesList;
    Context mContext;

    public AdapterTestList(String[] pagesList, Context mContext) {
        this.pagesList = pagesList;
        this.mContext = mContext;
    }

    @NonNull
    @Override
    public PageHold onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View adapterView = LayoutInflater.from(mContext).inflate(R.layout.adapter_test_list, parent, false);
        return new PageHold(adapterView);
    }

    @Override
    public void onBindViewHolder(@NonNull PageHold holder, int position) {
        if (pagesList == null || pagesList.length == 0) {
            return;
        }
        holder.txtText.setText(pagesList[position]);
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String page = pagesList[position];
                if (page.equalsIgnoreCase(mContext.getString(R.string.person_info))) {
                    mContext.startActivity(new Intent(mContext, PersonActivity.class));

                } else if (page.equalsIgnoreCase(mContext.getString(R.string.sync_time))) {
                    mContext.startActivity(new Intent(mContext, TimeActivity.class));
                } else if (page.equalsIgnoreCase(mContext.getString(R.string.weather))) {
                    mContext.startActivity(new Intent(mContext, WeatherActivity.class));
                } else if (page.equalsIgnoreCase(mContext.getString(R.string.sleep))) {

                } else if (page.equalsIgnoreCase(mContext.getString(R.string.screen_off_time))) {
                    mContext.startActivity(new Intent(mContext, ScreenOutActivity.class));

                } else if (page.equalsIgnoreCase(mContext.getString(R.string.reminder_time))) {
                    mContext.startActivity(new Intent(mContext, ReminderActivity.class));
                }else if (page.equalsIgnoreCase(mContext.getString(R.string.reset_device))){
                    mContext.startActivity(new Intent(mContext, ResetActivity.class));
                }

            }
        });

    }

    @Override
    public int getItemCount() {
        return pagesList == null ? 0 : pagesList.length;
    }

    class PageHold extends RecyclerView.ViewHolder {
        TextView txtText;

        public PageHold(@NonNull View itemView) {
            super(itemView);
            txtText = itemView.findViewById(R.id.text_page);
        }
    }

    public void destroyAdapter() {
        mContext = null;
        pagesList = null;
    }
}
